package spring.framework.beans.factory.support;

import spring.framework.beans.BeansException;
import spring.framework.beans.factory.BeanFactory;
import spring.framework.beans.factory.config.BeanDefinition;

/**
 * @author fun.pengzh
 * @class spring.framework.beans.factory.support.AbstractBeanFactory
 * @desc
 * @since 2021-09-18
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String name) throws BeansException {
        Object bean = getSingleton(name);
        if (null == bean) {
            final BeanDefinition beanDefinition = getBeanDefinition(name);
            bean = createBean(name, beanDefinition);
        }
        return bean;
    }

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException;

    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException;

}
